#include "CIntroState.h"
#include "Utility.h"
#include "CInputManager.h"
#include "CDirectWrite.h"
#include "CCamera.h"
#include "CTimer.h"



CIntroState::CIntroState()
{

}


CIntroState::~CIntroState()
{

}


void CIntroState::Enter()
{
	LOG("Entering CIntroState");

	button.SetMovable(true);
	button.LoadButtonImage("Resource/Images/button-final.jpg");
	button.SetText("Button");
	button.SetXTextOff(45);
	button.SetYTextOff(55);

	background = CRender::GetInstance()->LoadTexture2DFromFile("Resource/Images/test1.png");

	D3DXMATRIX scale;
	D3DXMATRIX mat;

	D3DXMatrixScaling(&scale, (float)background->m_Width, (float)background->m_Height, 1.0f);
	D3DXMatrixTranslation(&mat, float(background->m_Width / 2.0f), 768.0f - float(background->m_Height / 2.0f), 0.1f);

	background->m_pSprite->matWorld = scale * mat;
}


bool CIntroState::GetInput()
{

	if(CInputManager::GetInstance()->MouseButtonDown(LEFTMOUSE_BUTTON))
	{
		showMe = true;
		Xpos = CInputManager::GetInstance()->MouseGetPosX();
		yPos = CInputManager::GetInstance()->MouseGetPosY();
	}
	else
	{
		showMe = false;
	}

	if(CInputManager::GetInstance()->KeyDown(DIK_W))
	{
		CCamera::GetInstance()->TranslateGlobalViewZ(CTimer::GetInstance()->GetDelta() * -5.0f);
	}

	if(CInputManager::GetInstance()->KeyDown(DIK_S))
	{
		CCamera::GetInstance()->TranslateGlobalViewZ(CTimer::GetInstance()->GetDelta() * 5.0f);
	}

	if(CInputManager::GetInstance()->KeyDown(DIK_A))
	{
		CCamera::GetInstance()->TranslateGlobalViewX(CTimer::GetInstance()->GetDelta() * 5.0f);
	}

	if(CInputManager::GetInstance()->KeyDown(DIK_D))
	{
		CCamera::GetInstance()->TranslateGlobalViewX(CTimer::GetInstance()->GetDelta() * -5.0f);
	}

	return true;
}


void CIntroState::Leave()
{
	LOG("Leaving CIntroState");

	
}


void CIntroState::Update(double delta)
{
	button.Update(delta);
}


void CIntroState::Render()
{
	//CDirectWrite::GetInstance()->DrawText("This is custom text!");

	CRender::GetInstance()->Render2D(background->m_pSprite);

	CRender::GetInstance()->Render();

	button.Render();

	CDirectWrite::GetInstance()->DrawText(CDirectWrite::EARTH, "This is custom text using EARTH font!", 50, 50, D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f));
	CDirectWrite::GetInstance()->DrawText(CDirectWrite::DEFAULT, "Boom I got shit going now!", 300, 400, D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f));

	/*if(showMe)
	{
		CDirectWrite::GetInstance()->DrawText(CDirectWrite::DEFAULT, "Follow the mouse!", Xpos - 125, yPos - 17, D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f));
	}*/
}


void CIntroState::StartUp()
{
	LOG("Starting up CIntroState");
}


void CIntroState::ShutDown()
{
	LOG("Shutting down CIntroState");
}

CIntroState* CIntroState::GetInstance()
{
	static CIntroState state;
	return &state;
}